<template>
    <div id="Detail">
        <div class="detail">
            <component :inputData="detailData"
                       :is="currentComponent"></component>
            <v-table :searchFlag="false"
                     :hasEdit="false"
                     :pageSize="pageSize"
                     :page="page"
                     :tableConfig="tableConfig"
                     :tableData="tableData"
                     :total="total"
                     @findData="getTableData"
                     @getTableData="getTableData"
                     @searhData="setSearhData"
                     @selectData="setSelectData"
                     @upData="getTableData"
                     ref="table"
                     v-if="flag"></v-table>
        </div>
    </div>

</template>

<script>
import detail from "commons/Detail";
import navMenu from "commons/NavMenu";
import baseMixin from "@/mixins/BaseMixin";
import table from 'commons/Table'

export default {
    name: "Detail",
    mixins: [baseMixin],
    data() {
        return {
            selectData: {},
            detailData: {
                adjustmentkey: "",
                receiptkey: "",
                storerkey: "",
                effectivedate: ""
            },
            detailNav: "1",
            componentConfig: [
                {
                    name: "particulars",
                    label: this.$t('common.info'),
                    component: () => import('./page/Particulars.vue')
                }
            ],
            flag: false,
            tableConfig: [
                {
                    label: this.$t('outbound.userlinenumber'),
                    prop: "adjustmentlinenumber",
                    input: "input",
                },
                {label: this.$t('in.receiptlinenumber'), prop: "receiptlinenumber", input: "input"},
                {
                    label: this.$t('config.sku'),
                    prop: "sku",
                    input: "input",
                },
                {label: this.$t('config.loc'), prop: "loc"},
                {
                    label: this.$t('bill.lot'),
                    prop: "lot",
                    input: "input",
                },
                {
                    label: this.$t('in.lpn'),
                    prop: "id",
                    input: "input",
                },
                {label: this.$t('in.adjustmentqty'), prop: "qty", input: "input"},
                {
                    label: "UOM",
                    prop: "uom",
                    input: "input",
                },
                {
                    label: this.$t('config.packaging'),
                    prop: "packkey",
                    input: "input",
                },
            ],
            tableData: [],
            pageSize: 10,
          page: 1,
            total: 10,
            searhData: {},
            temporary: []
        }
    },
    computed: {
        currentComponent() {
            return this.componentConfig[this.detailNav - 1].component;
        }
    },
    methods: {
        async getData() {
            try {
                let res = await this.$api.get(`/queryReceiptreversalByAdjustmentkey/${this.selectData.adjustmentkey}`);
                
                    this.detailData = res.bean;
                
            } catch (e) {
                this.$message.error(e);
            }
        },
        async getTableData(page, data) {

            try {
                let res = await this.$api.get(`/queryOrdetailListbyChoseReceiptkey/${this.detailData.receiptkey}/${page}`,);
                
                    this.tableData = res.page.list;
                  this.page = res.page.curPage;
                    this.pageSize = res.page.pageSize;
                    this.total = res.page.total;
                
            } catch (e) {
                this.$message.error(e);
            }
        },
        //搜索值
        setSearhData(data, up) {
            if (!up) {
                this.searhData = data;
            } else {
                this.searhData = data;
                this.getTableData(1, this.searhData);
            }
        },
        setSelectData(data) {
            this.temporary = data;
        },
    },
    mounted() {
        if (Object.keys(this.$store.state.skip).length !== 0) {
            let data = this.$store.state.skip;
            this.detailData = data.detail;
            this.flag = data.detailFlag;
            this.selectData = data.routeData;
            this.detailNav = data.detailNav;
            if (this.flag) {
                this.getTableData(1, {})
            }
        } else if (this.$store.state.newFlag) {
            let date = new Date();
            this.detailData.adjustmentkey = this.$store.state.routeId;
            this.detailData.effectivedate = date.getTime();
        } else {
            this.selectData = this.$store.state.routeData;
            this.getData();
        }

    },
    components: {
        "v-detail": detail,
        "v-navMenu": navMenu,
        "v-table": table
    },

}
</script>

<style scoped>
</style>
